package uy.com.cimarron.its.web.beans.menu;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

import org.primefaces.component.menuitem.MenuItem;
import org.primefaces.component.submenu.Submenu;
import org.primefaces.model.DefaultMenuModel;
import org.primefaces.model.MenuModel;
import org.springframework.context.annotation.Scope;

import uy.com.cimarron.its.web.beans.commons.BasicBean;
import uy.com.cimarron.its.web.beans.commons.BasicNavigation;

@ManagedBean(name=BasicBean.MENU_BEAN)
@Scope(BasicBean.REQUEST)
public class MenuBean extends BasicNavigation{

	private static final long serialVersionUID = 5893788688105675701L;
	private MenuModel model;

	public MenuBean() {
		model = new DefaultMenuModel();
		
		//First submenu
		Submenu submenu = new Submenu();
		submenu.setLabel("Herramientas");
		
		
		MenuItem all = new MenuItem();
		all.setValue("Todas");
		all.setUrl("/pages/grid.jsf");
		
		MenuItem search = new MenuItem();
		search.setValue("Todas");
		search.setUrl("/pages/grid.jsf");
		
		submenu.getChildren().add(search);
		
		model.addSubmenu(submenu);
		
		//Second submenuitsm
		submenu = new Submenu();
		submenu.setLabel("Submenu 2");
		
//		item = new MenuItem();
//		item.setValue("Menuitem 2.1");
//		item.setUrl("#");
//		submenu.getChildren().add(item);
		
//		item = new MenuItem();
//		item.setValue("Menuitem 2.2");
//		item.setUrl("#");
//		submenu.getChildren().add(item);
		
		model.addSubmenu(submenu);
	}

	public MenuModel getModel() {
		return model;
	}	
    
    public void save() {
		addMessage("Data saved");
	}
	
	public void update() {
		addMessage("Data updated");
	}
	
	public void delete() {
		addMessage("Data deleted");
	}
	
	public void addMessage(String summary) {
		FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary,  null);
		FacesContext.getCurrentInstance().addMessage(null, message);
	}
}